<?php 

namespace app\recordpen\controller;

use app\recordpen\model\FileTagModel;

class FileTagCore {
	/**
	 * 创建重点标注 - Core
	 */
	public static function createFileTagCore($fid, $tag) {
		$timestamp = time();
		$createData = [
			FileTagModel::FID => $fid,
			FileTagModel::TAG => $tag,
			FileTagModel::CREATE_TIME => $timestamp,
			FileTagModel::UPDATE_TIME => $timestamp,
		];
		$res = FileTagModel::create($createData);
		if ($res) {
			return operationRes(true, 'Create File Tag Successful', $res);
		}
		return operationRes(false, 'Create File Tag Failed');
	}

	/**
	 * 查询重点标注 - Core
	 */
	public static function selectFileTagCore($whereCondt) {
		$list = FileTagModel::where($whereCondt)->select();

		$returnData = [
			'list' => $list
		];
		return operationRes(true, 'Query Successful', $returnData);
	}

	/**
	 * 更新重点标注 - Core
	 */
	public static function updateFileTagCore($whereCondt, $updateData) {
		if (FileTagModel::where($whereCondt)->update($updateData)) {
			return operationRes(true, 'Update Successful');
		}
		return operationRes(false, 'Update Failed');
	}

	/**
	 * 验证重点标注是否存在 - Core
	 */
	public static function verifyFileTagIsExist($fid) {
		$whereCondt = [
			FileTagModel::FID => $fid,
			FileTagModel::IS_DELETE => 0
		];
		$res = self::selectFileTagCore($whereCondt);
		if (!empty($res->data->list)) {
			return operationRes(true, 'File Tag Is Exist', $res->data->list[0]);
		}
		return operationRes(false, 'File Tag Is Not Exist');
	}
}